#include <SPI.h>
#include <nRF24L01p.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);        // Create MFRC522 instanc


nRF24L01p transmitter(7,8);//CSN,CE

void setup(){
  delay(150);
  Serial.begin(115200);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  transmitter.channel(90);
  transmitter.TXaddress("Artur");
  transmitter.init();
  mfrc522.PCD_Init();
}

String message;
//int a=0;
void loop(){
  //delay(3000);
  message+= RFID();
  //message=a;
  //a++;
  if (message=="") {
  //Serial.print("K co gi");
  return;
    }  
    else {
      Serial.print(message);
      transmitter.txPL(message);
      transmitter.send(SLOW);
      message="";
    }
  
}
String RFID(){
  String Co ="";
  MFRC522::MIFARE_Key key;
        for (byte i = 0; i < 6; i++) {
                key.keyByte[i] = 0xFF;
        }
        // Look for new cards
        if ( ! mfrc522.PICC_IsNewCardPresent()) {
               return "";
        }

        // Select one of the cards
        if ( ! mfrc522.PICC_ReadCardSerial()) {
                return "";
        }
        
        // Now a card is selected. The UID and SAK is in mfrc522.uid.
        // Dump UID
        //Serial.print("Card UID:");  //Serial.print(mfrc522.uid.size);
        for (byte i = 0; i < mfrc522.uid.size; i++) {
                Co += mfrc522.uid.uidByte[i];
        }
        //Co="";
     
        mfrc522.PICC_HaltA();

        // Stop encryption on PCD
        mfrc522.PCD_StopCrypto1();
        //Serial.print(Co);
        return(Co);
        
        /*
      String TA= "201043990";
      String K = "13817818145";
      String T = "4218318145";
          Serial.print(Co); 
          if(Co==TA || Co == K || Co == T)
          {
            digitalWrite(led, HIGH);
            delay(3000);
            digitalWrite(led, LOW);
            delay(3000);
          }*/
          
      
}
